
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[paObtenerCausasAlta] 

	 @ID INT = Null,
	 @PorPermiso BIT  
AS 
SET NOCOUNT ON
SET DATEFORMAT DMY
DECLARE @Consulta varchar(3000)

SET @Consulta = 'SELECT     idCausaAlta AS ID, Descripcion , Mnemo
FROM  dbo.tb_CausasAltas
WHERE 1=1 '

IF @ID IS NOT NULL
	SET @Consulta = @Consulta + ' AND IDCausaAlta = '+CONVERT(VARCHAR(12),@ID)
/*	
If @PorPermiso=1
	SET @Consulta = @Consulta + ' AND IDCausaAlta in (Select distinct RC.IdCausaAlta From Tb_RelRolCausasAlta RC 
			INNER JOIN Tb_RelUsuarioRol RU On RC.IdRol = RU.IdRol 
			INNER JOIN Tb_Usuarios U On U.IdUsuario = RU.IdUsuario
			Where U.NTUser = '''+ system_user+ ''' )'
*/
EXEC (@Consulta)
GO

GRANT EXECUTE ON  [dbo].[paObtenerCausasAlta] TO [GestionInstitucional]
GRANT EXECUTE ON  [dbo].[paObtenerCausasAlta] TO [PersonalDocente]
GRANT EXECUTE ON  [dbo].[paObtenerCausasAlta] TO [PersonalDocenteDireccion]
GRANT EXECUTE ON  [dbo].[paObtenerCausasAlta] TO [SoloVer]
GO
